from globalCommon import *
from PyQt5 import QtWidgets, uic
from PyQt5.QtCore import *
from PyQt5.QtWidgets import *
from PyQt5.QtGui import *
class UiMainWindow(QtWidgets.QMainWindow):
    def __init__(self):
        super().__init__()
        uic.loadUi('control.ui', self)
        self.initData()
        self.start.clicked.connect(self.start_click)
        self.pause.clicked.connect(self.pause_click)
        self.recover.clicked.connect(self.recover_click)
        self.stop.clicked.connect(self.stop_click)
        self.saveConfig.clicked.connect(self.save_config_click)
        self.sortWin.clicked.connect(self.sort_win_click)
        self.choseFile.clicked.connect(self.chose_file_click)
    def initData(self):
        self.setTableData()
        self.installPath.setText('C:\\Users\\')
        self.openNumberRadio.setChecked(True)
        self.model1Radio.setChecked(True)
        self.pwOpenRadio.setChecked(True)
        self.threadNumber.setText('2')
        self.qtNumber.setText('5')
        self.byNumber.setText('10')
        self.hjNumber.setText('15')

    def setTableData(self):
        # #水平方向，表格大小拓展到适当的尺寸
        self.tableWidget.horizontalHeader().setSectionResizeMode(QHeaderView.Stretch)
        self.tableWidget.horizontalHeader().setSectionResizeMode(0, QHeaderView.Interactive)

        self.tableWidget.setColumnWidth(0, 80)

        infos = dn.get_list()
        self.tableWidget.setColumnCount(5) #设置6列
        self.tableWidget.setRowCount(18) #设置8行

        for i, item in enumerate(infos):
            print(i, item.index, item.name)
            self.tableWidget.setItem(i, 0, QTableWidgetItem(item.name))
            self.tableWidget.setItem(i, 1, QTableWidgetItem(''))
            self.tableWidget.setItem(i, 2, QTableWidgetItem(''))
            self.tableWidget.setItem(i, 3, QTableWidgetItem(''))
            self.tableWidget.setItem(i, 4, QTableWidgetItem(''))

    # 开始
    def start_click(self):
        print('start_click!')

    # 暂停
    def pause_click(self):
        print('pause_click!')
    # 恢复
    def recover_click(self):
        print('recover_click!')
    # 停止
    def stop_click(self):
        print('stop_click!')
    # 保存配置
    def save_config_click(self):
        print('save_config_click!')
    # 排序窗口
    def sort_win_click(self):
        print('sort_win_click!')
    def chose_file_click(self):
        file_path, _ = QFileDialog.getOpenFileName(self, "Open File", "", "Text Files (*.txt);;All Files (*)")
        if file_path:
            self.userPath.setText(file_path)

if __name__ == "__main__":
    # 创建 Dnconsole 类的实例
    # node = dn.get_node_info(0, "PLAY Wallet")
    # clickNode(0, node)
    # nodes = dn.list_all_node(0)
    # print(nodes)
    # dn.launch(0)
    # info = dn.get_cur_activity_xml(0)
    # print(info)
    app = QtWidgets.QApplication([])
    window = UiMainWindow()
    window.show()
    app.exec_()


